
import { EventEmitter } from './EventEmitter';

class MessageManager extends EventEmitter {
    private originUrl?: string;
    private currentCode?: number;
    private currentMessage?: string;
    private originData?: unknown;
    getOriginUrl() {
        return this.originUrl;
    }
    getCurrentCode() {
        return this.currentCode;
    }
    getCurrentMessage() {
        return this.currentMessage;
    }
    getOriginData() {
        return this.originData;
    }
    setOriginUrl(v: string) {
        this.originUrl = v;
    }
    setCurrentCode(v: number) {
        this.currentCode = v;
    }
    setCurrentMessage(v: string) {
        this.currentMessage = v;
    }
    setOriginData(v: unknown) {
        this.originData = v;
    }
    setData(v: { origin: string; code: number; message: string; data: unknown }) {
        this.originUrl = v.origin;
        this.currentCode = v.code;
        this.currentMessage = v.message;
        this.originData = v.data;
    }

    static instance = new MessageManager();

    static getInstance() {
        if (!MessageManager.instance) {
            MessageManager.instance = new MessageManager();
        }
        return MessageManager.instance;
    }
}
export { MessageManager };
